export function openNewPage(url) {
	window.open(url)
}
// goLinePage
export function goLinePage(){
	gtag('event', 'goLinePage', {
	  'event_category' : 'none',
	  'event_label' : 'none'
	});
	openNewPage('https://page.line.me/687bnmmo')
}
// registerSuccess 注册成功
export function registerSuccess() {
	gtag('event', 'registerSuccess', {
	  'event_category' : 'none',
	  'event_label' : 'none'
	});
	history.pushState({}, 0, addUrlParams('registerSuccess'));
	setTimeout(() => {
		history.pushState({}, 0, delUrlParam('registerSuccess'));
	}, 2000)
}
// addCartSuccess 添加购物车
export function addCardSuccess() {
	gtag('event', 'addCartSuccess', {
	  'event_category' : 'none',
	  'event_label' : 'none'
	});
	history.pushState({}, 0, addUrlParams('addCardSuccess'));
	setTimeout(() => {
		history.pushState({}, 0, delUrlParam('addCardSuccess'));
	}, 2000)
}
// paymentSuccess 支付成功
export function paymentSuccess() {
	gtag('event', 'paymentSuccess', {
	  'event_category' : 'none',
	  'event_label' : 'none'
	});
	history.pushState({}, 0, addUrlParams('paymentSuccess'));
	setTimeout(() => {
		history.pushState({}, 0, delUrlParam('paymentSuccess'));
	}, 2000)
}

function delUrlParam(param) {
	let obj = new window.URL(window.location.href);
	obj.searchParams.delete(param);
	return obj.href;
}

function addUrlParams(param) {
	let obj = new window.URL(window.location.href);
	obj.searchParams.append(param, true)
	return obj.href;
}
